package com.luhuiguo.cms.server.handler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Component;

import com.luhuiguo.cms.server.service.ChannelService;
import com.luhuiguo.cms.shared.rpc.RemoveChannel;
import com.luhuiguo.cms.shared.rpc.RemoveChannelResult;
import com.luhuiguo.gwt.dispatcher.server.ActionHandler;
import com.luhuiguo.gwt.dispatcher.server.ExecutionContext;
import com.luhuiguo.gwt.dispatcher.shared.exception.ActionException;

@Component
public class RemoveChannelHandler implements ActionHandler<RemoveChannel, RemoveChannelResult> {

    @Autowired
    private ChannelService channelService;

    @Override
    @PreAuthorize("isAuthenticated()")
    public RemoveChannelResult execute(RemoveChannel action, ExecutionContext context) throws ActionException {

        Long id = action.get();

        channelService.deleteChannelCascade(id);

        return new RemoveChannelResult(id);

    }

    @Override
    public Class<RemoveChannel> getActionType() {
        return RemoveChannel.class;
    }

    @Override
    public void rollback(RemoveChannel action, RemoveChannelResult result, ExecutionContext context)
            throws ActionException {

    }

}
